// index.js
// 获取应用实例
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast.js';
const app = getApp()

Page({
  data: {
    motto: 'Hello World',
    show: false,
  },
  showPopup(){
    this.setData({show:true});
  },
  onClose(){
    this.setData({show:false});
  },
  toast01Fun(){
    Toast('我是提示文案，建议不超过十五字~');
  },
  toast02Fun(){
    Toast.loading({
      message: '加载中...',
      forbidClick: true,//通过 forbidClick 属性可以禁用背景点击
      loadingType: 'spinner',//通过 loadingType 属性可以自定义加载图标类型
    });
  },
  toast03Fun(){
    Toast.success('成功文案');
  },
  toast04Fun(){
    Toast.fail('失败文案');
  },
  toast05Fun(){
    const toast = Toast.loading({
      duration: 0, // 持续展示 toast
      forbidClick: true,
      message: '倒计时 3 秒',
      selector: '#custom-selector',
    });
    
    let second = 3;
    const timer = setInterval(() => {
      second--;
      if (second) {
        toast.setData({
          message: `倒计时 ${second} 秒`,
        });
      } else {
        clearInterval(timer);
        Toast.clear();
      }
    }, 1000);
  },
  toast06Fun(){
    Toast({
      type: 'success',
      mask: true,
      message: '提交成功',
      onClose: () => {
        console.log('执行OnClose函数');
      },
    });
  },
  navigateToPage: function(event) {
    var page = event.currentTarget.dataset.page;
    wx.navigateTo({
      url: '/pages/'+page+'/'+page+'?param1=value1&param2=value2'
    });
  }
})
